package com.lrs.java.j2se_self.thread;

public class TestDeathLock implements Runnable {
	public int flag ;
	static Object ob1 = new Object();
	static Object ob2 = new Object();
	
	public static void main(String[] args){
		TestDeathLock td1 = new TestDeathLock();
		TestDeathLock td2 = new TestDeathLock();
		td1.flag = 0;
		td2.flag = 1;
		Thread t1 = new Thread(td1);
		Thread t2 = new Thread(td2);
		t1.start();
		t2.start();
	}
	public void run(){
		System.out.println(flag);
		if(flag == 0){
			synchronized(ob1){
				try{
					Thread.sleep(1000);
				}catch(InterruptedException e){
					e.printStackTrace();
				}
				synchronized(ob2){
					System.out.println("ob2");
				}
			}
			
		}
		if(flag == 1){
			synchronized(ob2){
				try{
					Thread.sleep(1000);
				}catch(InterruptedException e){
					e.printStackTrace();
				}
				synchronized(ob1){
					System.out.println("ob1");
				}
			}
		}
	}
}
